﻿using MediatR;
using Production_Get.API.DTO;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.Produce.ManifestInfos;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.MaterialManagement.Mang
{
    public class ItemManifestInfoMangHandler : IRequestHandler<ItemManifestInfoMangCommon, Result>
    {
        private readonly IBaseRepositoryGet<ItemManifestInfo> ItemManifestInfoRepository;
        public ItemManifestInfoMangHandler(IBaseRepositoryGet<ItemManifestInfo> itemManifestInfoRepository)
        {
            ItemManifestInfoRepository = itemManifestInfoRepository;
        }

        public async Task<Result> Handle(ItemManifestInfoMangCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };
            string sql = "SELECT * FROM ItemManifestInfo Where ChooseId=" + request.ChooseId;
            var list = ItemManifestInfoRepository.GetAll(sql, default).FirstOrDefault();
            if (list != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = list;
                result.Msg = "显示成功";
            }

            return result;
        }
    }
}
